//
//  WSConcernViewController.m
//  GroupFourFM
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 GroupFour. All rights reserved.
//

#import "WSConcernViewController.h"
#import "WSConcernTableViewCell.h"
#import "WSBmob.h"
#import <BmobSDK/Bmob.h>
#import "WHAuthorDetailViewController.h"

@interface WSConcernViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *myArray;

@end

@implementation WSConcernViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myArray = [NSMutableArray array];
    
    NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uId"];
    [[WSBmob shareBmob] selectRelationWithUid:uid tableName:@"Collect_author" block:^(id results) {
       
        NSMutableArray *arr = [NSMutableArray arrayWithArray:results];
        for (BmobObject *obj in arr) {
            
            WSAuthorModel *author = [[WSAuthorModel alloc] init];
            author.nickname = [obj objectForKey:@"authorName"];
            author.personDescribe = [obj objectForKey:@"authorContent"];
            author.largeLogo = [obj objectForKey:@"headImage"];
            author.uid = [[obj objectForKey:@"authorId"] integerValue];
            [self.myArray addObject:author];
        }
        
        [self.myTableView reloadData];
    }];
    
    [self createTableView];
}

#pragma mark - 创建TableView

-(void)createTableView{
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:(UITableViewStylePlain)];
    [self.view addSubview:self.myTableView];
    
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.view);
        
    }];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.myTableView registerClass:[WSConcernTableViewCell class] forCellReuseIdentifier:@"WSConcernTableViewCell"];
    self.myTableView.rowHeight = 100;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.myArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WSConcernTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WSConcernTableViewCell"];
    cell.authorM = self.myArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    WHAuthorDetailViewController *authorDetail = [[WHAuthorDetailViewController alloc] init];
    authorDetail.uid = [self.myArray[indexPath.row] uid];
    [self.navigationController pushViewController:authorDetail animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
